#!/usr/bin/env python3
# encoding: utf-8
import reshape
#check result file  diff to resultTest.txt
def checkResult(retReally,retTest):
    resultTestData = []
    with open(retTest) as f:
        resultTestData = f.readlines()
    print("except result is ")
    for resultline in resultTestData:
        print(resultline)
    resultReallyData =[]
    with open(retReally) as f:
        resultReallyData = f.readlines()
    print("except result is ")
    for resultline in resultReallyData:
        print(resultline)
    testFailed = False
    retCount = 0
    if len(resultTestData) == len(resultReallyData):
        for ret in resultReallyData:
            if len(ret) == len(resultTestData[retCount]) and ret in resultTestData[retCount] :
                print("below this line ok ,test one line sucess  ")
                print(ret)
                print(resultTestData[retCount])
            else:
                testFailed = True
            retCount += 1

    else:
        testFailed = True
    if True == testFailed:
        print("test failed ,pls check your code ")
    else:
        print("test sucessfull ,you got the right result")





#main test code
db = reshape.MyKvDB("country , 1999 , 2000")
db.displayTableData()
db.InsetItems("A ,0.7K,2K")
db.InsetItems("B ,37K,80K")
db.InsetItems("C ,212K,213K")
db.displayTableData()
#except  output result  like this ,it can be auto test in  future
# {'A ': {'1999': '0.7k', '2000': '2k'}}
# {'B ': {'1999': '37k', '2000': '80k'}}
# {'C ': {'1999': '212k', '2000': '213k'}}
db.reshapeOutput()
db.outputToFile("result.txt")
# country,year,cases
# {'A ': {'1999': '0.7K', '2000': '2K'}}
# {'B ': {'1999': '37K', '2000': '80K'}}
# {'C ': {'1999': '212K', '2000': '213K'}}
# {'A ': {'1999': '0.7K', '2000': '2K'}}
# {'B ': {'1999': '37K', '2000': '80K'}}
# {'C ': {'1999': '212K', '2000': '213K'}}

#test  function checkResult  given diffent result ,excepted for failed
checkResult("result.txt","resultTest.txt")
#test function checkResult given same result ,excepted for success
checkResult("result.txt","resultTest.txt")
#test  MyKvDB result
checkResult("result.txt","resultTest.txt")
